package com.yehongyu.mytools.core.thread;

public class SerialNum {
	
	// The next serial number to be assigned
	private static int nextSerialNum = 0;

	private static ThreadLocal<Integer> serialNum = new ThreadLocal<Integer>() {
		protected synchronized Integer initialValue() {
			return new Integer(nextSerialNum++);
		}
	};

	public static int get() {
		serialNum.set(nextSerialNum++);
		return serialNum.get().intValue();
	}
	 

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(SerialNum.get());
		System.out.println(SerialNum.get());

	}

}
